package com.zhouyu.exampleThread.lockTest;

import java.util.concurrent.locks.ReentrantLock;

import lombok.extern.log4j.Log4j2;

/**
 * @Description:
 */
@Log4j2
public class Myservice extends Thread {
  private static ReentrantLock lock=new ReentrantLock();
  public void sayHelo(){
    lock.lock();
    log.info("线程：{}已经上锁",Thread.currentThread().getName());
    //在这里释放锁，之后的代码就没有线程同步了；而notify()之后还会执行代码，执行完释放锁
    lock.unlock();

  }

  @Override
  public void run() {
    sayHelo();
  }


}
